// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
// import request from "@/utils/request.js";

/**
 * 获取购物车列表
 * @param numType boolean true 购物车数量,false=购物车产品数量
 */
export const getCartCounts = (data) =>
  uni.http({
    url: 'user/cart/count',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 获取购物车列表
 *
 */
export const getCartList = (data) =>
  uni.http({
    url: 'user/cart/lst',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 修改购物车数量
 * @param int cartId  购物车id
 * @param int number 修改数量
 */
export const changeCartNum = (cartId, data) =>
  uni.http({
    url: 'user/cart/change/' + cartId,
    method: 'POST',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 清除购物车
 * @param object ids
 */
export const cartDel = (data) =>
  uni.http({
    url: 'user/cart/delete',
    method: 'POST',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 订单列表
 * @param object data
 */
export function getOrderList(data) {
  return uni.http({
    url: 'order/list',
    data,
    requestType: 'service',
    noAuth: false,
  })
}

/**
 * 订单产品信息
 * @param string unique
 */
export function orderProduct(orderId) {
  return uni.http({
    url: 'reply/product/' + orderId,
    requestType: 'service',
    noAuth: false,
  })
}

/**
 * 订单评价
 * @param object data
 *
 */
export function orderComment(id, data) {
  return uni.http({
    url: 'reply/' + id,
    requestType: 'service',
    data,
    method: 'POST',
    noAuth: false,
  })
}
/**
 * 退款订单删除
 * @param string id
 *
 */
export function unOrderDel(id) {
  return uni.http({
    url: 'refund/del/' + id,
    method: 'POST',
    requestType: 'service',
    data: {
      noAuth: true,
    },
  })
}
/**
 * 订单支付
 * @param object data
 */
export function orderPay(id, data) {
  return uni.http({
    url: 'order/pay/' + id,
    requestType: 'service',
    data,
    method: 'POST',
    noAuth: false,
  })
}

/**
 * 积分商品订单支付
 * @param object data
 */
export function integralOrderPay(id, data) {
  return request.post('order/points/pay/' + id, data)
}
/**
 * 订单统计数据
 */
export function orderData() {
  return uni.http({
    url: 'order/number',
    requestType: 'service',
    noAuth: false,
  })
}

/**
 * 订单取消
 * @param string id
 *
 */
// export function orderCancel(id){
//   return request.post('order/cancel',{id:id});
// }

/**
 * 未支付订单取消
 * @param string id
 *
 */
export function unOrderCancel(id) {
  return uni.http({
    url: 'order/cancel/' + id,
    requestType: 'service',
    method: 'POST',
    noAuth: false,
  })
}

/**
 * 删除已完成订单
 * @param string uni
 *
 */
export function orderDel(id) {
  return uni.http({
    url: 'order/del/' + id,
    requestType: 'service',
    method: 'POST',
    noAuth: false,
  })
}

/**
 * 订单详情
 * @param string uni
 */
export function getOrderDetail(id) {
  return uni.http({
    url: 'order/detail/' + id,
    requestType: 'service',
    noAuth: false,
  })
}

/**
 * 订单详情
 * @param string uni
 */
export function groupOrderDetail(id) {
  return uni.http({
    url: 'order/group_order_detail/' + id,
    requestType: 'service',
    noAuth: false,
  })
}

// 支付状态订单

/**
 * 再次下单
 * @param string uni
 *
 */
export function orderAgain(data) {
  return uni.http({
    url: 'user/cart/again',
    requestType: 'service',
    data,
    method: 'POST',
    noAuth: false,
  })
}

/**
 * 订单收货
 * @param string uni
 *
 */
export function orderTake(ID) {
  return uni.http({
    url: 'order/take/' + ID,
    requestType: 'service',
    method: 'POST',
    noAuth: false,
  })
}

/**
 * 订单查询物流信息
 * @returns {*}
 */
export function express(id) {
  return uni.http({
    url: 'order/express/' + id,
    requestType: 'service',
    method: 'POST',
    noAuth: false,
  })
}
/**
 * 退款单查询物流信息
 * @returns {*}
 */
export function refundOrderExpress(merId, id) {
  return uni.http({
    url: `server/${merId}/refund/express/${id}`,
    requestType: 'service',
    noAuth: false,
  })
}
/**
 * 获取退款理由
 *
 */
export function ordeRefundReason() {
  return request.get('order/refund/reason')
}

/**
 * 订单退款审核
 * @param object data
 */
export function orderRefundVerify(data) {
  return request.post('order/refund/verify', data)
}

/**
 * 订单确认获取订单详细信息
 * @param string cartId
 */
export function orderConfirm(data) {
  return uni.http({
    url: 'order/check',
    method: 'post',
    data,
    requestType: 'service',
    noAuth: false,
  })
}
/**
 * 订单确认获取订单详细信息
 * @param string cartId
 */
export const getOrderConfirm = (data) => {
  return uni.http({
    url: 'v2/order/check',
    method: 'post',
    data,
    requestType: 'service',
    noAuth: false,
  })
}

/**
 * 获取当前金额能使用的优惠卷
 * @param string price
 *
 */
export function getCouponsOrderPrice(price, data) {
  return uni.http({
    url: 'coupons/order/' + price,
    data,
    requestType: 'service',
    noAuth: false,
  })
}

// 生成订单
export function orderCreate(data) {
  return uni.http({
    url: 'order/create',
    method: 'post',
    data,
    requestType: 'service',
    noAuth: true,
  })
}
// 新的生成订单
export const createOrder = (data) =>
  uni.http({
    url: 'v2/order/create',
    method: 'post',
    data,
    requestType: 'service',
    noAuth: true,
  })
// 未支付订单
export function groupOrderList(data) {
  return request.get('order/group_order_list', data, { noAuth: true })
}

// 批量退款列表
export function refundBatch(id) {
  return uni.http({
    url: 'refund/batch_product/' + id,
    requestType: 'service',
    noAuth: true,
  })
}

// 退款商品
export function refundProduct(id, data) {
  return uni.http({
    url: 'refund/product/' + id,
    requestType: 'service',
    data,
    noAuth: true,
  })
}

// 申请退款
export function refundApply(id, data) {
  return uni.http({
    url: 'refund/apply/' + id,
    requestType: 'service',
    data,
    method: 'POST',
    noAuth: true,
  })
}

// 退款理由
export function refundMessage() {
  return uni.http({
    url: 'common/refund_message',
    requestType: 'service',
    noAuth: true,
  })
}

// 退款列表
export function refundList(data) {
  return request.get('refund/list', data, { noAuth: true })
}

// 退款详情
export function refundDetail(id) {
  return request.get('refund/detail/' + id, { noAuth: true })
}

// 物流列表
export function expressList() {
  return uni.http({
    url: 'common/express',
    requestType: 'service',
    noAuth: false,
  })
}

// 退回商品提交
export function refundBackGoods(id, data) {
  return request.post('refund/back_goods/' + id, data, { noAuth: true })
}

// 退款记录删除
export function refundDel(id) {
  return request.post('refund/del/' + id, { noAuth: true })
}

// 退款记录删除
export function refundExpress(id) {
  return request.get('refund/express/' + id, { noAuth: true })
}

// 核销二维码
export function verifyCode(id) {
  return uni.http({
    url: 'order/verify_code/' + id,
    requestType: 'service',
    noAuth: false,
  })
}
/**
 * 预售尾款支付
 * @param object data
 */
export function presellOrderPay(id, data) {
  return request.post('presell/pay/' + id, data)
}

/**
 * 发票订单
 * @param object data
 */
export function receiptOrder(data) {
  return request.get('user/receipt/order', data)
}
/**
 * 发票订单
 * @param object data
 */
export function getReceiptOrder(id) {
  return request.get('user/receipt/order/' + id)
}
/**
 * 发票订单
 * @param object data
 */
export function getCallBackUrlApi(key) {
  return request.get('common/pay_key/' + key, {}, { noAuth: true })
}
/**
 * 发票订单
 * @param object data
 */
export function develiveryDetail(id) {
  return request.get(`order/delivery/${id}`)
}
/**
 * 订单申请开票
 * @param object data
 */
export function applyInvoiceApi(id, data) {
  return uni.http({
    url: `order/receipt/${id}`,
    method: 'POST',
    data,
    requestType: 'service',
    noAuth: false,
  })
}
/**
 * 退款单取消申请
 * @param object data
 */
export function refundCancelApi(id) {
  return request.post(`refund/cancel/${id}`)
}
